package com.cmbc.bean;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.function.Supplier;


/**
 * @author jianghaoqiang
 * @Date 2022/5/22
 */
public class CreateBySupplier {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.registerBean(User2.class, new Supplier<User2>() {
            @Override
            public User2 get() {
                User2 user2=new User2();
                user2.setName("xiaoming");
                return user2;
            }
        });
        applicationContext.refresh();
        User2 user2=applicationContext.getBean("user2",User2.class);
        System.out.println(user2.getName());
    }
}
